package com.yqg.protection.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.protection.common.Result;
import com.yqg.protection.entity.HistoryJh;
import com.yqg.protection.mapper.HistoryJhMapper;
import com.yqg.protection.service.IHistoryJhService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * HistoryJhController 前端控制器
 * @author zxf
 * @since 2025-08-29
 */
@RestController
@RequestMapping("/history-jh")
public class HistoryJhController {

    @Resource
    private IHistoryJhService historyJhService;

    @Resource
    private HistoryJhMapper historyJhMapper;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody HistoryJh historyJh) {
        return Result.success(historyJhService.saveOrUpdate(historyJh));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        HistoryJh historyJh =historyJhService.getById(id);
        return Result.success(historyJhService.saveOrUpdate(historyJh));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<HistoryJh> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
       List<HistoryJh> list=  historyJhService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(historyJhService.getById(id));
    }
    /**
     *  分页查询
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           Long equipmentInputStoreId,
                           String startTime,
                           String endTime) {
        pageNum = pageNum * pageSize - pageSize;
        List<HistoryJh> historyJhs = historyJhMapper.findPage(pageNum, pageSize, equipmentInputStoreId, startTime, endTime);
        Long count = historyJhMapper.findPageCount(equipmentInputStoreId, startTime, endTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("record", historyJhs);
        map.put("total", count);
        return Result.success(map);
    }

}

